<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace app\adapay\model;

class AdminPay extends \app\BaseModel
{
    protected $name = "massage_adapay_admin_pay";
    public function dataAdd($data)
    {
        $data["create_time"] = time();
        $res = $this->insert($data);
        return $res;
    }
    public function dataUpdate($dis, $data)
    {
        $res = $this->where($dis)->update($data);
        return $res;
    }
    public function dataList($dis, $page)
    {
        $data = $this->where($dis)->order("status desc,id desc")->paginate($page)->toArray();
        return $data;
    }
    public function dataInfo($dis)
    {
        $data = $this->where($dis)->find();
        return !empty($data) ? $data->toArray() : [];
    }
    public function updateOne($id)
    {
        $user_id = $this->where(["id" => $id])->value("user_id");
        $res = $this->where(["user_id" => $user_id])->where("id", "<>", $id)->update(["status" => 0]);
        return $res;
    }
    public function adminPay($uniacid, $pay_price)
    {
        $insert = ["uniacid" => $uniacid, "pay_price" => $pay_price, "true_price" => $pay_price, "order_code" => orderCode()];
        $res = $this->dataAdd($insert);
        $id = $this->getLastInsID();
        $adapay_model = new \longbingcore\wxcore\Adapay($uniacid);
        $pay_record_model = new PayRecord();
        $res = $adapay_model->createPay($insert["order_code"], $insert["pay_price"], "1", "alipay_qr");
        if($res["status"] == "succeeded" && isset($res["expend"])) {
            $insert = ["uniacid" => $uniacid, "order_code" => $insert["order_code"], "adapay_code" => $insert["order_code"], "adapay_id" => $res["id"], "pay_price" => $insert["pay_price"], "true_price" => $insert["pay_price"], "type" => "Adapay", "order_id" => $id];
            $pay_record_model->dataAdd($insert);
        }
        return $res;
    }
    public function orderResult($order_code, $adapay_id)
    {
        $data = $this->dataInfo(["order_code" => $order_code, "pay_type" => 1]);
        if(!empty($data)) {
            $update = ["pay_time" => time(), "pay_type" => 2, "adapay_id" => $adapay_id];
            $this->dataUpdate(["id" => $data["id"]], $update);
        }
        return true;
    }
}

?>